import React, { createContext, useReducer } from 'react';
// 读取存储数据
export const ColorContext = createContext({})
export const UPDATE_COLOR = "UPDATE_COLOR"
const reducer = (state,action)=>{
  switch(action.type){
      case UPDATE_COLOR:
          return action.color
    default:
        return state
  }
}
export const Color = props=>{
    // 第一个值传方法们第二个传初始值
    const [color,dispatch]=useReducer(reducer,'blue')
    console.log(color,dispatch)
    return (
        // 共享出去的状态变成了color和dispatch,color是变量，dispatch1是函数,如果不共享出去dispatch，你是没办法完成按钮的相应事件的
        // {color: "blue", dispatch: ƒ}
    <ColorContext.Provider value={{color,dispatch}}>{props.children}</ColorContext.Provider>
    )
}